package com.mongdb.demo.controller;

import com.mongdb.demo.model.SysUser;
import com.mongdb.demo.model.SysUserDetails;
import com.mongdb.demo.service.SysUserService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/userTest")
public class SysUserTestController {

    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("/saveUserSubList")
    public Object saveUserSubList(String user_id,String user_name){
        SysUser user=new SysUser();
        user.setUser_id(user_id);
        user.setUser_name(user_name);
        user.setPassword("ffff12312wq");
        user.setCreateTime(new DateTime().toString("yyyy-MM-dd HH:mm:ss"));

        SysUserDetails details1 = new SysUserDetails();
        details1.setUser_id("4");
        details1.setSex("2");
        details1.setPhone("123qw12311");

        SysUserDetails details2 = new SysUserDetails();
        details2.setUser_id("14");
        details2.setSex("2");
        details2.setPhone("123qwe1");

        user.setDetails(new ArrayList<>());
        user.getDetails().add(details1);
        user.getDetails().add(details2);
        sysUserService.saveUser(user);
        return "ok";
    }

    @RequestMapping("/saveUser")
    public Object saveUser(String user_id,String user_name){
        SysUser user=new SysUser();
        user.setUser_id(user_id);
        user.setUser_name(user_name);
        user.setPassword("ffff12312wq");
        user.setCreateTime(new DateTime().toString("yyyy-MM-dd HH:mm:ss"));
        sysUserService.saveUser(user);
        return "ok";
    }


}
